package com.tarena.lbs.activity.rpc;

import com.tarena.lbs.activity.api.ActivityApi;
import com.tarena.lbs.activity.api.pojo.ActivityDto;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@DubboService
public class ActivityApiImpl implements ActivityApi {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ActivityRepository activityRepository;

    @Override
    public Boolean activityVisible(Integer userId, Integer activityId) {
        return false;
    }

    @Override
    public ActivityDto getActivityById(Integer activityId) {
        ActivityDto activityDto = new ActivityDto();
        try {
            if(activityRepository.selectById(activityId) != null){
                ActivityVO activityVO = activityService.activityDetail(activityId);
                BeanUtils.copyProperties(activityVO, activityDto);
                return activityDto;
            }else{
                return null; //若找不到活动，则返回null
            }
        }catch (BusinessException e) {
            throw new RuntimeException(e);
        }
    }
}
